package com.jcrj.task;

import com.jcrj.dao.UserDao;
import com.jcrj.entity.OTask;
import com.jcrj.entity.OUser;
import com.jcrj.service.MessageService;
import com.jcrj.util.AplicationUtil;
import com.jcrj.util.DateUtil;
import java.util.Date;
import java.util.List;
import org.springframework.context.ApplicationContext;

public class ScheduleTask {
	public void scheduleWarn() {
		MessageService messageService = (MessageService) AplicationUtil.getContext().getBean("messageService");
		UserDao userDao = (UserDao) AplicationUtil.getContext().getBean("userDao");
		String nowDate = DateUtil.DateToString(new Date());
		String hql = "from OTask o where o.startTime <=to_date('" + nowDate + "','yyyy-mm-dd') and o.endTime>=to_date('" + nowDate
				+ "','yyyy-mm-dd') and o.alertTime is not null";
		List<OTask> list = userDao.findByHql(hql);
		if ((list != null) && (!list.isEmpty()))
			for (OTask task : list)
				if ("week".equals(task.getCycle())) {
					if ((DateUtil.getNowDateWeek().equals(task.getWeek()))
							&& (DateUtil.maxMunites(task.getStartHour().intValue(), task.getStartMunite().intValue(), task.getAlertTime().doubleValue()) < 5L)
							&& (DateUtil.maxMunites(task.getStartHour().intValue(), task.getStartMunite().intValue(), task.getAlertTime().doubleValue()) >= 0L)) {
						OUser user = (OUser) userDao.getObject(new OUser(), task.getUserId().intValue());
						if ((user.getPhone() != null) && (!"".equals(user.getPhone()))) {
							messageService.send(user.getPhone(), "您有新日程关于" + task.getTitle().trim() + ",请尽快处理！");
						}
						if ((task.getNotifyUserId() != null) && (!"".equals(task.getNotifyUserId()))) {
							String userHql = "from OUser where id in(" + task.getNotifyUserId() + ")";
							List<OUser> users = userDao.findByHql(userHql);
							if ((users != null) && (!users.isEmpty())) {
								for (OUser u : users) {
									if ((u.getPhone() != null) && (!"".equals(u.getPhone())))
										messageService.send(u.getPhone(), "您有新知会日程关于" + task.getTitle().trim() + ",请尽快处理！");
								}
							}
						}
					}
				} else if ("month".equals(task.getCycle())) {
					if ((DateUtil.getNowDateDay().equals(task.getMonthDay()))
							&& (DateUtil.maxMunites(task.getStartHour().intValue(), task.getStartMunite().intValue(), task.getAlertTime().doubleValue()) < 5L)
							&& (DateUtil.maxMunites(task.getStartHour().intValue(), task.getStartMunite().intValue(), task.getAlertTime().doubleValue()) >= 0L)) {
						OUser user = (OUser) userDao.getObject(new OUser(), task.getUserId().intValue());
						if ((user.getPhone() != null) && (!"".equals(user.getPhone()))) {
							messageService.send(user.getPhone(), "您有新日程关于" + task.getTitle().trim() + ",请尽快处理！");
						}
						if ((task.getNotifyUserId() != null) && (!"".equals(task.getNotifyUserId()))) {
							String userHql = "from OUser where id in(" + task.getNotifyUserId() + ")";
							List<OUser> users = userDao.findByHql(userHql);
							if ((users != null) && (!users.isEmpty())) {
								for (OUser u : users) {
									if ((u.getPhone() != null) && (!"".equals(u.getPhone()))) {
										messageService.send(u.getPhone(), "您有新知会日程关于" + task.getTitle().trim() + ",请尽快处理！");
									}
								}
							}
						}
					}
				} else if ((DateUtil.maxMunites(task.getStartHour().intValue(), task.getStartMunite().intValue(), task.getAlertTime().doubleValue()) < 5L)
						&& (DateUtil.maxMunites(task.getStartHour().intValue(), task.getStartMunite().intValue(), task.getAlertTime().doubleValue()) >= 0L)) {
					OUser user = (OUser) userDao.getObject(new OUser(), task.getUserId().intValue());
					if ((user.getPhone() != null) && (!"".equals(user.getPhone()))) {
						messageService.send(user.getPhone(), "您有新日程关于" + task.getTitle().trim() + ",请尽快处理！");
					}
					if ((task.getNotifyUserId() != null) && (!"".equals(task.getNotifyUserId()))) {
						String userHql = "from OUser where id in(" + task.getNotifyUserId() + ")";
						List<OUser> users = userDao.findByHql(userHql);
						if ((users != null) && (!users.isEmpty()))
							for (OUser u : users)
								if ((u.getPhone() != null) && (!"".equals(u.getPhone())))
									messageService.send(u.getPhone(), "您有新知会日程关于" + task.getTitle().trim() + ",请尽快处理！");
					}
				}
	}
}

/*
 * Location: /Volumes/work/oa/WEB-INF/classes/ Qualified Name:
 * com.jcrj.task.ScheduleTask JD-Core Version: 0.6.0
 */